package com.dhq.util;

import java.util.Random;

/**
 * 测试线程间数据污染
 */
public class ThreadSharedDataDirty {
    //线程共享的数据
    private static int data=0;

    public static void main(String[] args) {
        for (int i=0;i<2;i++){
            new Thread(new Runnable() {
                @Override
                public void run() {
                    data = new Random().nextInt();
                    System.out.println(Thread.currentThread().getName()+":"+data);
                    new A().get();
                    new B().get();
                }
            }).start();
        }
    }

    static class A{
        public void get(){
            System.out.println("A =="+Thread.currentThread().getName()+":"+data);
        }
    }

    static class B{
        public void get(){
            System.out.println("B =="+Thread.currentThread().getName()+":"+data);
        }
    }
}
